package cn.school.controller.prevention;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.common.utils.SysUserUtils;
import cn.school.prevention.entity.Scope;
import cn.school.prevention.service.ScopeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "t_prevention_scope => 防控范围表")
@RequestMapping("/scope")
public class ScopeController {

    @Autowired
    private ScopeService scopeService;



    @ApiOperation("scopePageList => 分页查询防控信息表")
    @PostMapping(value = "/scopePageList")
    public CommonResult<CommonPage<Scope>> scopePageList(@RequestBody Scope scope) {
        IPage<Scope> scopeIPage = scopeService.scopePageList(scope);
        return CommonResult.success(CommonPage.restPage(scopeIPage));
    }

    @ApiOperation("list => 分页查询防控信息表")
    @PostMapping(value = "/pageList")
    public CommonResult<CommonPage<Scope>> list(@RequestBody Scope scope) {
        IPage<Scope> page = scopeService.page(scope);
        return CommonResult.success(CommonPage.restPage(page));
    }


    @ApiOperation("list => 分页查询防控信息表")
    @PostMapping(value = "/teacherPageList")
    public CommonResult<CommonPage<Scope>> teacherPageList(@RequestBody Scope scope) {
        String user = SysUserUtils.getSysUser().getUsername();
        scope.setTeacherId(user);

        IPage<Scope> page = scopeService.page(scope);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("updateScope => 修改防控信息表")
    @PostMapping("/updateScope")
    public CommonResult<Integer> updateScope(@RequestBody Scope scope) {
        int num = scopeService.update(scope);
        if (num > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
